<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        .todo-enter-active,.todo-leave-active{
            transition:  all 2s;
        }
        .todo-enter,.todo-leave-to{
            opacity: 0;
            transform: translateX(-100%);
        }
        .todo-leave,.todo-enter-to{
            opacity: 1;
            transform: translateX(0);
        }
    </style>
</head>
<body>
    <div id="app">
      <input v-model="newTodo"/>
      <button @click="addTodo">添加</button>
      <transition-group name="todo" tag="ul">
        <li v-for="todo in todos" :key="todo.id">
            <span>{{todo.text}}</span> <button @click="removeTodo(todo.id)">删除</button>
        </li>
      </transition-group>
    </div>
    <script src="vue.js"></script>
    <script>
        var vm = new Vue({
            el:'#app',
            data:{
                newTodo:'',
                todos:[
                    {id:1,text:'item1'},
                    {id:2,text:'item2'},
                    {id:3,text:'item3'}
                ]
            },
            methods:{
                addTodo(){
                    this.todos.push(
                        {
                            id:this.todos.length+1,
                            text:this.newTodo
                        }
                    );
                    this.newTodo = '';
                },
                removeTodo(id){
                    let index = this.todos.findIndex(todo=>todo.id === id);
                    this.todos.splice(index,1);
                }
            }
        });
    </script>
</body>
</html>